﻿
@{
    ViewBag.Title = "货品库存";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var warehouses = ViewBag.Warehouses as List<IOA.MES.DataAccess.VModel.VUserWarehouse>;
    var customers = ViewBag.Customers as List<IOA.MES.DataAccess.VModel.VCustomer>;
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CustomerName">客户名称：</label>
                        <div class="layui-input-inline">
                            <select id="selCustomer" lay-search>
                                <option value="">所有客户</option>
                                @foreach (var item in customers)
                                {
                                    <option value="@item.CustomerCode">@item.CustomerName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.OrderNo">订单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="orderNo" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkorderNo">工单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="workOrderNo" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CabinetNo">柜号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="cabinetNo" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.PackNo">打包编号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="packNo" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <a id="btnExport" href="javascript:void(0)" target="_blank" class="layui-btn layuiadmin-btn-list layui-btn-normal">
                            <i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'laydate', 'form'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    laydate = layui.laydate,
                    form = layui.form;

                var options = {
                    elem: '#table'
                    , url: '/Warehouse/QueryProductStorages'
                    , method: "post"
                    , where: { customerCode: "", orderNo: "", workOrderNo: "", cabinetNo: "", packNo: "" }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 60 }
                        , { field: 'WarehouseName', title: '仓库', width: 120 }
                        , { field: 'Location', title: '库位', width: 150 }
                        , { field: 'CustomerWarehouseName', title: '客户仓库', width: 120 }
                        , { field: 'CustomerName', title: '客户名称', width: 120 }
                        , { field: 'OrderNo', title: '订单号', width: 150 }
                        , { field: 'WorkOrderNo', title: '工单号', width: 200 }
                        , { field: 'WorkshopName', title: '生产车间', width: 120 }
                        , { field: 'CabinetNo', title: '柜号', width: 150 }
                        , { field: 'PackNo', title: '打包编号', width: 200 }
                        , { field: 'ProductCode', title: '成品料号', width: 200 }
                        , { field: 'ProductName', title: '成品名称', width: 200 }
                        , { field: 'ProductSpecs', title: '成品规格', width: 200 }
                        , { field: 'Quantity', title: '包装数量', width: 100 }
                        , { field: 'DetailQuantity', title: '组件数量', width: 100 }
                        , { field: 'QLevel', title: '等级', width: 100 }
                        , { field: 'PowerLevel', title: '功率', width: 100 }
                        , { field: 'NameplateModel', title: '铭牌型号', width: 150 }
                        , { field: 'CurrentLevel', title: '档位', width: 100 }
                        , { field: 'ComponentColor', title: '组件颜色', width: 100 }
                        , { field: 'BatterySpecs', title: '电池片规格', width: 200 }
                        , { field: 'BatteryFactory', title: '电池片厂家', width: 100 }
                        , { field: 'CreateTimeStr', title: '入库时间', width: 160 }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.where.customerCode = $("#selCustomer").val().trim();
                    options.where.orderNo = $("input[name=orderNo]").val().trim();
                    options.where.workOrderNo = $("input[name=workOrderNo]").val().trim();
                    options.where.cabinetNo = $("input[name=cabinetNo]").val().trim();
                    options.where.packNo = $("input[name=packNo]").val().trim();

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }

                $("#btnExport").click(function () {
                    var paras = new Array();
                    paras.push("customerCode=" + $("#selCustomer").val().trim());
                    paras.push("orderNo=" + $("input[name=orderNo]").val().trim());
                    paras.push("workOrderNo=" + $("input[name=workOrderNo]").val().trim());
                    paras.push("cabinetNo=" + $("input[name=cabinetNo]").val().trim());
                    paras.push("packNo=" + $("input[name=packNo]").val().trim());

                    $(this).attr("href", "/Warehouse/ExportProductStorages?" + paras.join("&"));
                });
            });
        }
    </script>
}
